#pragma once

#include "imagebutton.h"
#include "imageclipstrip.h"

class MixedButton : public ImageButton
{
protected:
	/** what text to draw in this button (if anything) */
	ImageClipStrip m_textGraphics;
public:
	ImageClipStrip * getTextGraphics(){return &m_textGraphics;}
	void copy(const MixedButton & b)
	{
		ImageButton::copy(b);
		m_textGraphics.copy(b.m_textGraphics);
	}
	void setText(const char * a_text)
	{
		m_textGraphics.createStringStrip(a_text);
		SRect * area = getArea();
		if(area->getDimension().isZero())
		{
			SRect contentArea(SPoint(0,0), m_textGraphics.getDimension());
			setArea(contentArea);
		}
	}
	void refreshArea()
	{
		SPoint iDim(m_clip.clip.getDimension());
		SPoint tDim(m_textGraphics.getDimension());
		SPoint dim(iDim.getX()+tDim.getX(),tDim.getY()>iDim.getY()?tDim.getY():iDim.getY());
		getArea()->setDimension(dim);
	}
	MixedButton(const ImageClip & a_icon, const char * a_text):ImageButton()
	{setButtonImage(a_icon);setText(a_text);refreshArea();}
	void draw(SDL_Surface * a_surface)
	{
		// must use copy of area because SDL_FillRect modifies the value...
		SRect area(*getArea());
		VSDL_FillRect(a_surface, &area, 
			getMasterPanel()->getColor((isOn()||(isOver()&&isPressed()))
			?MasterPanel::COLOR_ACTIVE
			:MasterPanel::COLOR_BG));
		area.set(*getArea());
		SPoint p(area.getPosition());
		m_clip.draw(a_surface, area.getMin(), ImageClip::DEFAULT_TRANSPARENT_INDEX);
		p.addX(m_clip.clip.getWidth());
		m_textGraphics.draw(a_surface, p);
		p.addX(m_textGraphics.getDimension().getX());
	}
};